package com.jiutong.meipengdai.utils;

import android.app.Activity;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by suxi on 2017/7/1.
 */

public class PermissionUtil {

    public static boolean checkSelfPermission(Activity activity, String... permission) {

        List<String> pers = new ArrayList<>();
        //检查系统是否开启了读写权限;
        for (String pms : permission) {
            if (ContextCompat.checkSelfPermission(activity, pms)
                    != PackageManager.PERMISSION_GRANTED) {
                pers.add(pms);
            }
        }

        if(pers.size() < 1){
            return true; //所有权限已开启
        }

        String[] persArray = new String[pers.size()];
        pers.toArray(persArray);

        ActivityCompat.requestPermissions(activity, persArray, persArray.length);
        return false;
    }
}
